﻿<div style="background:#fbf9fe" ms-controller="KHLXR">
    <div ms-if="isHasDataQX=='Y'">
        <!--<div class="weui_cells_title">基本信息</div>-->
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">姓名</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input ms-duplex="modelData.UserXM" type="text" placeholder="(必填)" class="weui_input szhl szhl_require" />
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">对应客户</label></div>
                <div class="weui_cell_bd weui_cell_primary" ms-visible="!mpid||modelData.KHID">
                    <!--<select ms-duplex="modelData.KHID" class="szhl weui-select" id="kh">
                        <option value="0">请选择客户</option>
                        <option ms-repeat-item="ColumnData" ms-attr-value="item.ID" ms-attr-selected="item.ID==modelData.KHID?'selected':''">{{item.KHName}}</option>
                    </select>-->
                    <input type="text" id="conKH" placeholder="请选择对应客户" ms-duplex="modelData.KHID" class="szhl szhl_getKH single weui_input" />
                </div>
                <div class="weui_cell_bd weui_cell_primary" ms-visible="mpid&&!modelData.KHID">
                    <input ms-duplex="modelData.Company" type="text" placeholder="请输入客户" class="weui_input" style="width:85%;" />
                </div>
                <div class="weui_cell_ft" ms-visible="mpid&&!modelData.KHID">
                    <input type="button" value="新增" ms-click="addmpkh()" class="button button-fill button-success " />
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">手机</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input ms-duplex="modelData.TelePhone" type="text" placeholder="(必填)" class="weui_input szhl_require" />
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">性别</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <select ms-duplex="modelData.UserSex" class="weui-select">
                        <option value="">请选择性别</option>
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">电话</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input ms-duplex="modelData.MobilePhone" type="text" placeholder="请输入电话" class="weui_input" />
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">职务</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input ms-duplex="modelData.Position" type="text" placeholder="请输入职位" class="weui_input" />
                </div>
            </div>
            <div class="extdiv"></div>
        </div>
        <div class="weui_cells_title">备注</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">
                    <textarea ms-duplex="modelData.Remark" rows="3" placeholder="请输入备注" class="weui_textarea"></textarea>
                </div>
            </div>
        </div>

        <div class="weui_cells_title">详细信息<a class="show-up" ms-click="isZK()" id="zk">展开</a></div>
        <div ms-if="isDeploy == 1">
            <div class="weui_cells weui_cells_form">
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">分机</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input ms-duplex="modelData.Extension" type="text" placeholder="请输入分机" class="weui_input" />
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">传真</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input ms-duplex="modelData.FixNo" type="text" placeholder="请输入传真" class="weui_input" />
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">学历</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input ms-duplex="modelData.Education" type="text" placeholder="请输入学历" class="weui_input" />
                    </div>
                </div>
                <!--<div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">公司</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input ms-duplex="modelData.Company" type="text" placeholder="请输入公司" class="weui_input" />
                    </div>
                </div>-->
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">部门</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input ms-duplex="modelData.Department" type="text" placeholder="请输入部门" class="weui_input" />
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">邮箱</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input ms-duplex="modelData.EMail" type="text" placeholder="请输入邮箱" class="weui_input" />
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">QQ</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input ms-duplex="modelData.QQ" type="text" placeholder="请输入QQ" class="weui_input" />
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">微信</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input ms-duplex="modelData.Weixin" type="text" placeholder="请输入微信" class="weui_input" />
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">网址</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input ms-duplex="modelData.WebSite" type="text" placeholder="请输入网址" class="weui_input" />
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">生日</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input type="text" placeholder="请选择生日" id="appDate" ms-duplex="modelData.Birthday" class="weui_input" />
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">邮编</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input ms-duplex="modelData.PostCode" type="text" placeholder="请输入邮编" class="weui_input" />
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label label">地址</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input ms-duplex="modelData.Address" type="text" placeholder="请输入地址" class="weui_input" />
                    </div>
                </div>
            </div>
        </div>
        <div class="weui_cells_title">图片上传</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">
                    <input type="text" ms-duplex="modelData.Files" class="wximgupload" style="display:none;" />
                </div>
            </div>
        </div>
    </div>
    <div ms-if="isHasDataQX=='N'">
        <!--<div class="weui_cells_title">基本信息</div>-->
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">姓名</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.UserXM}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">对应客户</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{khname}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">手机</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.TelePhone}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">性别</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.UserSex}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">电话</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.MobilePhone}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">职务</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.Position}}
                </div>
            </div>
        </div>
        <div class="extdiv"></div>
        <div class="weui_cells_title">备注</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.Remark|html}}
                </div>
            </div>
        </div>
        <div class="weui_cells_title">详细信息</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">分机</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.Extension}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">传真</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.FixNo}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">学历</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.Education}}
                </div>
            </div>
            <!--<div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">公司</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.Company}}
                </div>
            </div>-->
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">部门</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.Department}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">邮箱</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.EMail}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">QQ</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.QQ}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">微信</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.Weixin}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">网址</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.WebSite}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">生日</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <div ms-if="modelData.Birthday">{{modelData.Birthday|date('yyyy-MM-dd')}}</div>
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">邮编</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.PostCode}}
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label label">地址</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.Address}}
                </div>
            </div>
        </div>
        <div class="weui_cells_title">图片上传</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">
                    <div class="viewimg">{{modelData.Files}}</div>
                </div>
            </div>
        </div>
    </div>
</div>



<script>
    var tempmodel = avalon.define({
        $id: "KHLXR",
        ColumnData: [],
        name: "联系人管理",
        tpData: [],
        wximg: "",
        dataid: "",
        khname: "",
        isDeploy: 0,
        khid: ComFunJS.getQueryString("khid"),
        mpid: ComFunJS.getQueryString("mpid"),
        isZK: function () {
            if (tempmodel.isDeploy == 0) {
                tempmodel.isDeploy = 1;
                $("#zk").text("收起");
            }
            else {
                tempmodel.isDeploy = 0;
                $("#zk").text("展开");
            }
            //tempmodel.isDeploy == 0 ? 1 : 0;
        },
        inittemp: function (strId) {
          
            if (tempmodel.khid) {
                tempmodel.modelData.KHID = tempmodel.khid;
                $("#conKH").val(tempmodel.khid);
            }

            if (strId) {

                tempmodel.dataid = strId;
                $.getJSON('/API/VIEWAPI.ashx?Action=CRM_GETKHLXRMODEL', { P1: strId }, function (resultData) {

                    if (resultData.ErrorMsg == "") {
                        tempmodel.modelData = resultData.Result;
                        tempmodel.khname = resultData.Result1;
                        tempmodel.tpData = resultData.Result2;

                        if (tempmodel.modelData.Birthday && tempmodel.modelData.Birthday.length > 10) {
                            tempmodel.modelData.Birthday = tempmodel.modelData.Birthday.substring(0, 10);
                            $("#appDate").calendar({
                                value: [tempmodel.modelData.Birthday]
                            });
                        }
                        else {
                            $("#appDate").calendar({
                                value: []
                            });
                        }


                        ComFunJS.uploadimgnew(tempmodel.tpData);
                        ComFunJS.viewimg(tempmodel.tpData);

                        setTimeout(" ComFunJS.initForm()", 500)
                    }
                })
            } else if (tempmodel.mpid) {
                $.getJSON('/API/VIEWAPI.ashx?Action=CRM_GETKHMPMODEL', { P1: tempmodel.mpid }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        tempmodel.modelData = resultData.Result;
                        tempmodel.tpData = resultData.Result2;
                        if (tempmodel.modelData.Birthday && tempmodel.modelData.Birthday.length > 10) {
                            tempmodel.modelData.Birthday = tempmodel.modelData.Birthday.substring(0, 10);

                            $("#appDate").calendar({
                                value: [tempmodel.modelData.Birthday]
                            });
                        }
                        else {
                            $("#appDate").calendar({
                                value: []
                            });
                        }

                        if (tempmodel.modelData.Company) {
                            $.getJSON('/API/VIEWAPI.ashx?Action=CRM_KHISEXIST&r=' + Math.random(), { P1: tempmodel.modelData.Company }, function (resultData) {
                                if (resultData.ErrorMsg == "") {
                                    tempmodel.modelData.KHID = resultData.Result;
                                }
                            })
                        }

                        ComFunJS.uploadimgnew(tempmodel.tpData);
                        ComFunJS.viewimg(tempmodel.tpData);

                        setTimeout(" ComFunJS.initForm()", 500);
                    }
                })
            } else {
                $("#appDate").calendar({
                    value: []
                });

                ComFunJS.uploadimgnew();
                setTimeout(" ComFunJS.initForm()", 500)
            }
        },//初始化
        modelData: { "KHID": "0", "UserXM": "", "UserSex": "", "TelePhone": "", "Department": "", "Position": "", "EMail": "", "QQ": "", "Weixin": "", "Address": "", "Remark": "", "Files": "", "WebSite": "", "PostCode": "", "Birthday": "", "Extension": "", "FixNo": "", "Education": "", "Company": "", "Mailbox": "", "Others": "" },
        SaveData: function (callback) {
            if (tempmodel.mpid) {
                tempmodel.modelData.ID = "0";
            }
            tempmodel.modelData.Files = "";
            $("#imglist .tpli").each(function () {
                if ($(this).hasClass("wximg")) { //微信上传未处理的图片
                    if (tempmodel.wximg) {
                        tempmodel.wximg += ",";
                    }
                    tempmodel.wximg += $(this).attr("itemid");

                } else {
                    if (tempmodel.modelData.Files) {
                        tempmodel.modelData.Files = tempmodel.modelData.Files + ',' + $(this).attr("itemid");
                    }
                    else {
                        tempmodel.modelData.Files = $(this).attr("itemid");
                    }
                }

            })
            $.post("/API/VIEWAPI.ashx?ACTION=CRM_ADDKHLXR&mpid=" + tempmodel.mpid + "&r=" + Math.random(), { P1: JSON.stringify(tempmodel.modelData.$model), P2: tempmodel.wximg }, function (result) {

                return callback.call(this, $.parseJSON(result));
            });
        },
        addmpkh: function () {
            $.confirm("确认要新增客户【" + tempmodel.modelData.Company + "】？", function () {
                $.post('/API/VIEWAPI.ashx?Action=CRM_ADDMPKH&r=' + Math.random(), { "P1": tempmodel.modelData.Company }, function (result) {
                    result = JSON.parse(result)
                    if (result.ErrorMsg == "") {
                        tempmodel.modelData.KHID = result.Result.ID;
                        ComFunJS.initkh();
                        if (tempmodelkh) {
                            tempmodelkh.inittemp();
                        }
                        ComFunJS.winsuccess("新增成功");
                    } else {
                        if (result.Result) {
                            tempmodel.modelData.KHID = result.Result.ID;
                        }
                    }

                    if (tempmodelkh) {
                        tempmodelkh.defSetUsers();
                    }
                })
            })
        },
        Complate: function () {
            if (tempmodel.khid) {
                window.location.href = "/View_Mobile/UI/CRM/UI_KHGL_LIST.html?id=" + tempmodel.khid + "&r=" + Math.random();
            }
            else {
                window.location.href = "/View_Mobile/UI/CRM/UI_KHLXR_LIST.html?r=" + Math.random();
            }

        }
    });//# sourceURL=MHYGL.js;

</script>